func wiggleMaxLength(nums []int) int {
    if len(nums) <= 1 {
        return len(nums)
    }
    ans := 1
    preDiff := 0
    currDiff := 0
    for i:=0; i<len(nums)-1; i++ {
        currDiff = nums[i+1] - nums[i]
        if (currDiff>0 && preDiff<=0) || (currDiff<0 && preDiff>=0) {
            ans++
            preDiff = currDiff
        }
    }
    return ans
}